package com.Servlet;

import com.Service.Impl.UserServiceImpl;
import com.Service.UserService;
import com.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 冷俊杰
 * @Description: 根据手机号密码登录
 * @DateTime: 2022/6/2 10:38
 **/
@WebServlet("/UserServlet")
public class UserByNPServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserService service = new UserServiceImpl();
        String phone = req.getParameter("phone");
        String password = req.getParameter("password");
        String sessionCode = req.getParameter("code");
        System.out.println(sessionCode);
        if (sessionCode != null) {
            User user = service.UserByNP(phone, password);
            System.out.println(user);
            if (user != null) {
                req.getRequestDispatcher("/index.jsp").forward(req, resp);
            } else {
                req.getRequestDispatcher("/remainYHDL.jsp").forward(req, resp);
            }
            String code = req.getParameter("code");
        } else {
            req.getRequestDispatcher("/remainYHDL.jsp").forward(req, resp);
        }
    }
}